<?php
if (eregi(basename( __FILE__ ), $_SERVER['PHP_SELF'])) {
	print "<h1>Incorrect access</h1>You cannot access this file directly.";
	exit();
}

class xml_gallery{
	function playme(){	
		$code = AZLib::getParam('code');
		switch( $code ){
			case 'piclens_gallery':
				$this->piclens_gallery();
				break;
			case 'flash_view_gallery':
				$this->flash_view_gallery();
				break;
			default:
				$this->home();
				break;
		}
	}

	function home(){
		die("no_action");
	}

	function piclens_gallery(){
		$user_id  = (int)Url::get('user_id');
		if( $user_id ){
			$sql='select id, img_url, des FROM item_image WHERE user_id = '.$user_id.' AND root_id=0 ORDER BY id DESC LIMIT 0,200';
			 DB::query($sql);
			
			 if(DB::num_rows()){
			 	$entry='';
			 	 while($rows = DB::fetch_row()){
			 	 	$rows['des'] = ($rows['des']) ? $rows['des'] : "Image {$rows['id']}";
			 	 	$rows['des'] = trim( XMLLib::_xml_encode_attribute($rows['des']));
			 	 	
			 	 	if(ereg('/',$rows['img_url']))
			 	 		$url = trim( XMLLib::_xml_encode_attribute("http://".IMAGE_PATH."{$rows['img_url']}"));
			 	 	else
			 	 		$url = trim( XMLLib::_xml_encode_attribute("http://".IMAGE_PATH."uploaded/items/{$rows['img_url']}"));
			 	 	
			 	 	$entry .="
			 	 	<item>
			 	 			<title>".stripslashes($rows['des'])."</title>
							<link>$url</link>
							<guid>ID {$rows['id']}</guid>
							<media:thumbnail url=\"$url\" />
							<media:content url=\"$url\" />
					</item>
			 	 	";
			 	 }
			 	 
			 	 @header( "Content-type: text/xml" );
				 echo "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>
				 <rss version=\"2.0\" xmlns:media=\"http://search.yahoo.com/mrss\">
				 <channel>			
				 <title>Enbac.com</title>
				 <link>http://www.enbac.com/</link>
				 <description>Enbac.com - </description>
				 <logo url=\"style/images/logo.piclens.png\" />
				";
			 	 echo $entry;
			 	 echo "
			 	 </channel>
				 </rss>
				";
			 	 
			 }
			 else{
			 	die("no_info");
			 }
		}
		else{
			die("no_info");
		}
	}
	
	function flash_view_gallery(){
		$user_id  = (int)Url::get('user_id');
		if( $user_id ){
			$sql='select id, img_url, des FROM item_image WHERE user_id = '.$user_id.' AND root_id=0 ORDER BY id DESC LIMIT 0,200';
			 DB::query($sql);
			
			 if(DB::num_rows()){
				 $entry='';	 	
			 	 while($rows = DB::fetch_row()){
			 	 	$rows['des'] = ($rows['des']) ? $rows['des'] : "Image {$rows['id']}";
			 	 	
			 	 	$rows['des'] = trim( XMLLib::_xml_encode_attribute($rows['des']));
			 	 	
			 	 	if(eregi('/',$rows['img_url']))
			 	 		$url = trim( XMLLib::_xml_encode_attribute("http://".IMAGE_PATH."{$rows['img_url']}"));
			 	 	else
			 	 		$url = trim( XMLLib::_xml_encode_attribute("http://".IMAGE_PATH."uploaded/items/{$rows['img_url']}"));
			 	 	 	
				 	 $entry .="
							<photo imageurl=\"$url\" linkurl=\"http://enbac.com\">
								<title>{$rows['des']}</title>
							</photo>		 	 	
				 	 	";		 			 	 
			 	 }
	
			 	 
			 	 @header( "Content-type: text/xml" );
			 	 echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?".'>';
			 	 echo "<tiltviewergallery><photos>";
			 	 echo $entry;
			 	 echo "</photos></tiltviewergallery>";
			 }
			 else{
			 	die("no_info");
			 }
		}
		else{
			die("no_info");
		}
	}

}//class
?>